﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectEulerSolutions
{
    /*
     * 
     * The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.

Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.

     * 
     * */
    class Problem48 : IProblem
    {
        public string Calculate()
        {
            //taktika: (bruteforce, kao i uvijek :) ) i rofl, uspjelo je
            //jednostavno dodavat sve, i radit modulo sa 10^10. Ostat ce znamenke

            int n = 1000;

            long sum = 1;

            //iteracija koja broji ove glavne (1^1, 2^2 ... i^i)
            for (int i = 2; i <= n; i++)
            {
                sum += addingRecursion(i - 1, i);
                sum %= 10000000000L; //10 nula
            }


            return sum.ToString();
        }

        long addingRecursion(int level, int n)
        {
            long sum = 0;
            if (level <= 1)
            {
                sum = n * n;
                sum %= 10000000000L; //10 nula
            }
            else
            {
                sum = addingRecursion(level - 1, n) * n;
                sum %= 10000000000L; //10 nula
            }
            return sum;
        }
    }
}
